package cms.simmytech.service;

import cms.simmytech.mapper.TbContentMapper;
import cms.simmytech.model.TbContent;
import cms.simmytech.model.TbContentExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ContentService {
    @Autowired
    private TbContentMapper tbContentMapper;

    public PageInfo<TbContent> getContentList(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        TbContentExample example=new TbContentExample();
        example.setOrderByClause(" content_id  desc");
        List<TbContent> list= tbContentMapper.selectByExample(example);
        PageInfo<TbContent> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    public PageInfo<TbContent> querySearchByTitle(int pageNum, int pageSize,String  titleName){
        PageHelper.startPage(pageNum, pageSize);
        List<TbContent> list= tbContentMapper.selectByTitleName(titleName);
        PageInfo<TbContent> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    public void deleteContent(int id) {
        tbContentMapper.deleteByPrimaryKey(id);
    }
    public void AddContent(TbContent tbContent){
        tbContentMapper.insert(tbContent);
    }

    public TbContent getContentByContentID(int contentId){
        return tbContentMapper.selectByPrimaryKey(contentId);
    }
    public void updateContentByContentId(TbContent tbContent){
        tbContentMapper.updateByPrimaryKey(tbContent);
    }
}
